﻿using System.Collections.Generic;
using System.Web.Mvc;

namespace Yelper.Web.Validators {

    public class UrlValidator : DataAnnotationsModelValidator<UrlAttribute> {

        private readonly string _errorMessage;
        private readonly string _pattern;

        public UrlValidator(ModelMetadata metadata, ControllerContext context, UrlAttribute attribute)
            : base(metadata, context, attribute) {
            this._errorMessage = attribute.ErrorMessage;
            this._pattern = attribute.Pattern;
        }

        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules() {
            var rule = new ModelClientValidationRegexRule(this._errorMessage, this._pattern);
            return new[] { rule };
        }

    }
}